from src.day15.student_sys.student_mode import StuMode


class StuManager:
    def __init__(self):
        self.student = []
        self.num = 1

    def add_stu(self, name, age, s_class, email, address):
        sid = self.num
        students = StuMode(sid, name, age, s_class, email, address)
        self.student.append(students)
        self.num += 1


    def judge_stu(self, name, age, s_class, email, address):
        if not all([name, age, s_class, email, address]):
            return '您填写的信息不完整'
        try:
            int_age = int(age)
            if int_age < 0 or int_age > 200:
                return '您输入年龄超过限制'
        except:
            return '您输入的年龄格式不正确'
        return None


    def modify_stu(self, sid, name, age, s_class, email, address):
        student = self.get_student_by_id(sid)
        if student:
            student.name = name
            student.age = age
            student.s_class = s_class
            student.email = email
            student.address = address

    def get_student_by_id(self, sid):
        student = next((stu for stu in self.student if stu.sid == sid), None)
        return student


    def delete_stu(self, sid):
        self.student = [stu for stu in self.student if sid != stu.sid]

    def search_stu(self, search_name):
        find_stu = []
        for stu in self.student:
            if search_name in stu.name:
                find_stu.append(stu)
        return find_stu













